package com.coda.service.impl;

import com.coda.constant.StatusConstant;
import com.coda.entity.PaymentType;
import com.coda.mapper.PaymentTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaymentTypeService implements com.coda.service.PaymentTypeService {

    @Autowired
    private PaymentTypeMapper paymentTypeMapper;

    /**
     * 查看所有支付方式
     *
     * @return
     */
    @Override
    public List<PaymentType> paymentList() {
        List<PaymentType> list = paymentTypeMapper.getPaymentList();
        return list;
    }

    /**
     * 保存或更新支付方式
     *
     * @param paymentType
     */
    @Override
    public void saveOrUpdate(PaymentType paymentType) {
        //判断id是否存在，如果存在：更新，不存在：插入
        Long id = paymentType.getId();

        if (id == null) {
            paymentTypeMapper.insert(paymentType);
        }
        if (id != null) {
            paymentTypeMapper.update(paymentType);
        }


    }

    /**
     * 根据id删除支付方式
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        paymentTypeMapper.delete(id);
    }
}
